#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;

int n,m,t;
int a[100005],b[100005];

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    freopen("arena.in","r",stdin);
    freopen("arena.out","w",stdout);

    cin>>n>>m;
    rep(i,n) cin>>a[i];
    rep(i,m) cin>>b[i];
    string s;
    rep(i,__lg(n)+1) cin>>s;
    cin>>t;
    while(t--){
        int a[4];
        rep(i,4) cin>>a[i];
        cout<<0<<endl;
    }
    return 0;
}